﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBQLTV;

namespace DAO
{
    public class TacGiaDAO
    {
        public bool InsertTacGia(string TenTacGia)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                TACGIA tacGia_temp = entity.TACGIAs.FirstOrDefault(o => o.TenTacGia.Equals(TenTacGia));
                if (tacGia_temp != null)
                {
                    return false;
                }

                TACGIA tacgia = new TACGIA()
                {
                    TenTacGia = TenTacGia
                };
                entity.TACGIAs.AddObject(tacgia);
                entity.SaveChanges();
                return true;
            }
        }
        public static TACGIA GetTacGiaByName(string TenTacGia)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                TACGIA tacgia = entity.TACGIAs.FirstOrDefault(o => o.TenTacGia.Equals(TenTacGia));
                return tacgia;
            }
        }
        public List<TACGIA> GetListTacGia()
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                return entity.TACGIAs.ToList();
            }
        }
        public bool DeleteTacGia(string TenTacGia)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                TACGIA tacGia = entity.TACGIAs.FirstOrDefault(o => o.TenTacGia.Equals(TenTacGia));
                if (tacGia == null)
                    return false;
                else 
                {
                    entity.TACGIAs.DeleteObject(tacGia);
                    entity.SaveChanges();
                    return true;
                }
            }
        }
    }
}
